package com.steve.mac.tools.hadooptest.reducer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * designed by Steve Ke on 2017/12/19.
 *
 * @author Steve Ke
 *         e-mail  huangke7296@foxmail.com
 *         github  https://github.com/KoreHuang
 *         oschina https://git.oschina.net/steveKe
 * @version JDK 1.8.0_111
 * @since 2017/12/19
 */
public class MaxTemperatureReducer
        extends Reducer<Text,IntWritable,Text,IntWritable>{

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        List<Integer> operation = new ArrayList();
        values.forEach((pre)->{
            operation.add(pre.get());
        });

        context.write(key,
                new IntWritable(
                    operation
                    .parallelStream()
                    .reduce(Integer.MIN_VALUE,
                            (pre,item)->{
                                return item>pre?item:pre;
                            }
                    )
                )
        );

    }

}
